using System;
using System.Drawing;
using System.Runtime.Serialization;

namespace Motorway_Simulator.Components
{
    /// <summary>
    /// Traffic light component
    /// </summary>
    [Serializable()]
    public class TrafficLight : GraphicComponent, ISerializable
    {
        /// <summary>
        /// Holds the color
        /// </summary>
        private Color color;
        
        /// <summary>
        /// Hold the time
        /// </summary>
        private int realTime;

        /// <summary>
        /// Constructor to create traffic light object
        /// </summary>
        public TrafficLight()
            : base()
        {
            // Default settings
            color = new Color();
            color = Color.Red;
            realTime = 0;
        }

        /// <summary>
        /// Draws the road unit
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            throw new System.Exception("Not implemented");
        }

        /// <summary>
        /// Get/Set accessor method
        /// </summary>
        public Color Colour
        {
            set { color = value; }
            get { return color; }
        }

        /// <summary>
        /// To notify trafficlight that time has passed.
        /// </summary>
        public void Notify()
        {
            realTime++;
        }


        #region ISerializable Members

        /// <summary>
        /// Add value for serialization
        /// </summary>
        /// <param name="info">Infor</param>
        /// <param name="context">Context</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Color", color);
            info.AddValue("RealTime", realTime);
        }

        #endregion

        /// <summary>
        /// Is called to set values read from file
        /// </summary>
        /// <param name="info">Info</param>
        /// <param name="ctxt">ctxt</param>
        public TrafficLight(SerializationInfo info, StreamingContext ctxt)
        {
            color = (Color)info.GetValue("Color", typeof(Color));
            realTime = (int)info.GetValue("RealTime", typeof(int));
        }
    }
}